import { defineStore } from 'pinia'
import { GET_OPERATIONS,SET_OPERATIONS,REMOVE_OPERATIONS,GET_CHECKOPERATIONS,SET_CHECKOPERATIONS,REMOVE_CHECKOPERATIONS } from '@/utils/operation'
import { replaceRoute } from '@/utils/routerUtil'
// 业务数据
const useOperationStore = defineStore('operation', {
  state: () => {
    return {
      data: JSON.parse(GET_OPERATIONS()) || [],
      index: GET_CHECKOPERATIONS()
    }
  },
  actions: {
    // 更改选择业务
    updateCheck(idx){
      SET_CHECKOPERATIONS(idx)
      this.index=idx
      replaceRoute()
    },
    // 添加业务数据
    updateData(data){
      SET_OPERATIONS(JSON.stringify(data))
      this.data=data
    },
    // 清空业务数据
    clear(){
      this.data=[]
      this.index=0
      REMOVE_OPERATIONS()
      REMOVE_CHECKOPERATIONS()
    }
  },
  getters: {

  },
});
export default useOperationStore;